#!/bin/bash

# A script to enable custom behavior for starting Cassandra or DSE.
# This script should not run forever, but should instead background
# the long-running process.
# This script should exit with a status of 0 if the operation is a
# success, and a non-zero value otherwise.

# To enable this script, rename this file to start-cassandra and
# make sure that it's executable.
#
# Note: for this script to run properly the user running the agent 
# (cassandra by default) must have proper permissions to start
# and stop the DSE/Cassandra process (sudo is acceptable if your
# environment supports it).

export CASSANDRA_HOME="<%= @cassandra_path %>"
export CASSANDRA_CONF="<%= @conf_path %>"
export CASSANDRA_INCLUDE="$CASSANDRA_HOME/bin/cassandra.in.sh"

pid_file="<%= @run_path %>/cassandra.pid"
log_file="<%= @run_path %>/cassandra_agentstartup.log"

$CASSANDRA_HOME/bin/cassandra -p $pid_file >$log_file 2>&1
ret=$?

# accept exit status of 0 or 1
# (due to https://issues.apache.org/jira/browse/CASSANDRA-4271)
if [ "$ret" -eq "0" -o "$ret" -eq "1" ]; then
    exit 0
else
    exit $ret
fi

